package com.jlee.android.pimclient.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

import com.jlee.android.pimclient.PIMClientConstant;
import com.jlee.android.pimclient.R;

public class PIMClientCallLogSettingActivity extends Activity {
	CheckBox mCallNameCB;
	CheckBox mCallNumberCB;
	CheckBox mCallTypeCB;
	CheckBox mDurationCB;
	
	SharedPreferences mSettings;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.calllog_setting);
		setTitle(R.string.title_calllog_setting);

		mSettings = getSharedPreferences(PIMClientConstant.PREFS_NAME, MODE_PRIVATE);
		
		mCallNameCB = (CheckBox) findViewById(R.id.callName);
		mCallNumberCB = (CheckBox) findViewById(R.id.callNumber);
		mCallTypeCB = (CheckBox) findViewById(R.id.callType);
		mDurationCB = (CheckBox) findViewById(R.id.duration);

		final Button saveButton = (Button) findViewById(R.id.save);
		saveButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				doSave();
			}
			
		});
		
		initChecked();
	}

	private void initChecked() {
		mCallNameCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_CALLLOG_NAME, true));
		mCallNumberCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_CALLLOG_NUMBER, true));
		mCallTypeCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_CALLLOG_TYPE, true));
		mDurationCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_CALLLOG_DURATION, true));
	}
	
	void doSave() {
		Editor editor = mSettings.edit();

		editor.putBoolean(PIMClientConstant.PREFS_KEY_CALLLOG_NAME, 
				mCallNameCB.isChecked());
		editor.putBoolean(PIMClientConstant.PREFS_KEY_CALLLOG_NUMBER, 
				mCallNumberCB.isChecked());
		editor.putBoolean(PIMClientConstant.PREFS_KEY_CALLLOG_TYPE, 
				mCallTypeCB.isChecked());
		editor.putBoolean(PIMClientConstant.PREFS_KEY_CALLLOG_DURATION, 
				mDurationCB.isChecked());

		editor.commit();
		finish();
	}
}
